package com.ruoyi.project.system.member.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.common.utils.uniquekey.IdGererateFactory;
import com.ruoyi.project.system.coin.domain.Coin;
import com.ruoyi.project.system.coin.mapper.CoinMapper;
import com.ruoyi.project.system.coin.service.ICoinService;
import com.ruoyi.project.system.member.domain.Member;
import com.ruoyi.project.system.member.mapper.MemberMapper;
import com.ruoyi.project.system.member.service.IMemberService;
import com.ruoyi.project.system.order.order.service.IOrderOrderService;
import com.ruoyi.project.system.paylog.domain.PayLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * 小程序用户Service业务层处理
 * 
 * @author LCL
 * @date 2020-06-09
 */
@Service
public class MemberServiceImpl implements IMemberService 
{
    @Resource
    private IdGererateFactory idGererateFactory;
    @Autowired
    private MemberMapper memberMapper;
    @Autowired
    private CoinMapper coinMapper;
    @Autowired
    private ICoinService coinService;
    @Autowired
    private IMemberService memberService;
    @Autowired
    private IOrderOrderService orderOrderService;

    /**
     * 查询小程序用户
     * 
     * @param id 小程序用户ID
     * @return 小程序用户
     */
    @Override
    public Member selectMemberById(String id)
    {
        return memberMapper.selectMemberById(id);
    }

    /**
     * 查询小程序用户列表
     * 
     * @param member 小程序用户
     * @return 小程序用户
     */
    @Override
    public List<Member> selectMemberList(Member member)
    {
        return memberMapper.selectMemberList(member);
    }

    /**
     * 新增小程序用户
     * 
     * @param member 小程序用户
     * @return 结果
     */
    @Override
    public int insertMember(Member member)
    {
        member.setId(this.idGererateFactory.nextStringId());
        return memberMapper.insertMember(member);
    }

    /**
     * 修改小程序用户
     * 
     * @param member 小程序用户
     * @return 结果
     */
    @Override
    public int updateMember(Member member)
    {
        return memberMapper.updateMember(member);
    }

    /**
     * 删除小程序用户对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteMemberByIds(String ids)
    {
        return memberMapper.deleteMemberByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除小程序用户信息
     * 
     * @param id 小程序用户ID
     * @return 结果
     */
    @Override
    public int deleteMemberById(String id)
    {
        return memberMapper.deleteMemberById(id);
    }

    @Override
    public Member findOneByOpenId(String openid) {
        return this.memberMapper.findOneByOpenId(openid);
    }

    @Override
    public String[] findListPerson(String id) {
        return this.memberMapper.findListPerson(id);
    }

    @Override
    public Integer findOrderSumByIds(String[] personIds) {
        return this.memberMapper.findOrderSumByIds(personIds);
    }

    @Override
    public Double findOrderPriceSumByIds(String[] personIds) {
        return this.memberMapper.findOrderPriceSumByIds(personIds);
    }

    @Override
    public Integer findSumVipByIds(String[] personIds) {
        return this.memberMapper.findSumVipByIds(personIds);
    }

    @Override
    public List<Member> findMemberListPerson(String userId) {
        return this.memberMapper.findMemberListPerson(userId);
    }

    @Override
    public void upLv(Member introUser) {
        //判断用户当前等级
        Member select;
        int size=0;
        switch (introUser.getIsVip()){
            case 1:
                //判断下级会员数是否满足
                select = new Member();
                select.setIntroUser(introUser.getId());
                select.setIsVip(1);
                //查询下级会员的数量
                size = this.memberMapper.selectMemberList(select).size();
                //查询下级的下级的会员数量
                size=size+ this.memberMapper.findVipCountMember(introUser.getId(),1);
                if(size>=20){
                  //判断本月业绩是否达到15万
                    BigDecimal orderSumByType = this.coinMapper.findOrderSumByType(introUser.getId(), DateUtils.getNowDate(), 1);
                    //查询本月个人订单总额
                    BigDecimal sumOrder = this.orderOrderService.findSumCountByUid(introUser.getId(),0);
                    if((orderSumByType.add(sumOrder)).compareTo(new BigDecimal(150000))!=-1){
                        Member update = new Member();
                        update.setIsVip(2);
                        update.setId(introUser.getId());
                        this.memberMapper.updateMember(update);
                    }
                }
                break;
            case 2:
                //判断下级会员数是否满足
                select = new Member();
                select.setIntroUser(introUser.getId());
                select.setIsVip(2);
                size = this.memberMapper.selectMemberList(select).size();
                //查询下级的下级的会员数量
                size=size+ this.memberMapper.findVipCountMember(introUser.getId(),1);
                if(size>=10){
                  //判断本月业绩是否达到150万
                    BigDecimal orderSumByType = this.coinMapper.findOrderSumByType(introUser.getId(), DateUtils.getNowDate(), 1);
                    //查询本月个人订单总额
                    BigDecimal sumOrder = this.orderOrderService.findSumCountByUid(introUser.getId(),0);
                    if((orderSumByType.add(sumOrder)).compareTo(new BigDecimal(1500000))!=-1){
                        Member update = new Member();
                        update.setIsVip(3);
                        update.setId(introUser.getId());
                        this.memberMapper.updateMember(update);
                    }
                }
                break;
        }

    }

    @Override
    public void updateIntroUser(BigDecimal priceVip1, BigDecimal priceVip2, BigDecimal priceVip3, BigDecimal priceVip4, BigDecimal priceVip5, BigDecimal priceVip6, BigDecimal pricePush1, BigDecimal pricePush2, BigDecimal pricePush3, Member introUser, String orderNo, PayLog payLog,Member member) {

        //定义变量
        Coin coin;
        Coin coin1;
        Coin coin2;
        Coin coin3;
        Coin coin4;
        Coin coin5;
        Member introUser1;
        Member introUser2;
        Member introUser3;
        Member introUser4;
        Member introUser5;
        Member update1;
        Member update2;
        Member update3;
        Member update4;
        Member update5;
        Member update6;
        switch (member.getIsVip()){
            case 0:
                switch (introUser.getIsVip()){
                    case 1:
                        //新增收益记录
                        coin = new Coin();
                        coin.setCreated(DateUtils.getNowDate());
                        coin.setType(0);
                        coin.setStatus(0);
                        coin.setMemberId(introUser.getId());
                        coin.setNum(priceVip1);
                        coin.setResId(orderNo);
                        coin.setOrderPrice(payLog.getPrice());
                        this.coinService.insertHaoqiCoinRecord(coin);
//                        update1 = new Member();
//                        update1.setId(introUser.getId());
//                        update1.setCoin(introUser.getCoin().add(priceVip1));
//                        this.memberService.updateMember(update1);
                        introUser1 = this.memberService.selectMemberById(introUser.getIntroUser());
                        if(introUser1!=null){
                            switch (introUser1.getIsVip()){
                                case 1:
                                    //新增收益记录
                                    coin1=new Coin();
                                    coin1.setCreated(DateUtils.getNowDate());
                                    coin1.setType(0);
                                    coin1.setStatus(0);
                                    coin1.setMemberId(introUser1.getId());
                                    coin1.setNum(pricePush1);
                                    coin1.setResId(orderNo);
                                    coin1.setOrderPrice(payLog.getPrice());
                                    this.coinService.insertHaoqiCoinRecord(coin1);
//                                    update2 = new Member();
//                                    update2.setId(introUser1.getId());
//                                    update2.setCoin(introUser1.getCoin().add(pricePush1));
//                                    this.memberService.updateMember(update2);
                                    introUser2 = this.memberService.selectMemberById(introUser1.getIntroUser());
                                    if(introUser2!=null){
                                        switch (introUser2.getIsVip()){
                                            case 2:
                                                //新增收益记录
                                                coin2=new Coin();
                                                coin2.setCreated(DateUtils.getNowDate());
                                                coin2.setType(0);
                                                coin2.setStatus(0);
                                                coin2.setMemberId(introUser2.getId());
                                                coin2.setNum(priceVip4);
                                                coin2.setResId(orderNo);
                                                coin2.setOrderPrice(payLog.getPrice());
                                                this.coinService.insertHaoqiCoinRecord(coin2);
//                                                update3 = new Member();
//                                                update3.setId(introUser2.getId());
//                                                update3.setCoin(introUser2.getCoin().add(priceVip4));
//                                                this.memberService.updateMember(update3);
                                                introUser3 = this.memberService.selectMemberById(introUser2.getIntroUser());
                                                if(introUser3!=null){
                                                    switch (introUser3.getIsVip()){
                                                        case 2:
                                                            //新增收益记录
                                                            coin3=new Coin();
                                                            coin3.setCreated(DateUtils.getNowDate());
                                                            coin3.setType(0);
                                                            coin3.setStatus(0);
                                                            coin3.setMemberId(introUser3.getId());
                                                            coin3.setNum(pricePush2);
                                                            coin3.setResId(orderNo);
                                                            coin3.setOrderPrice(payLog.getPrice());
                                                            this.coinService.insertHaoqiCoinRecord(coin3);
//                                                            update4 = new Member();
//                                                            update4.setId(introUser3.getId());
//                                                            update4.setCoin(introUser3.getCoin().add(pricePush2));
//                                                            this.memberService.updateMember(update4);
                                                            introUser4 = this.memberService.selectMemberById(introUser3.getIntroUser());
                                                            if(introUser4!=null){
                                                                switch (introUser4.getIsVip()){
                                                                    case 3:
                                                                        //新增收益记录
                                                                        coin4=new Coin();
                                                                        coin4.setCreated(DateUtils.getNowDate());
                                                                        coin4.setType(0);
                                                                        coin4.setStatus(0);
                                                                        coin4.setMemberId(introUser4.getId());
                                                                        coin4.setNum(priceVip6);
                                                                        coin4.setResId(orderNo);
                                                                        coin4.setOrderPrice(payLog.getPrice());
                                                                        this.coinService.insertHaoqiCoinRecord(coin4);
//                                                                        update5 = new Member();
//                                                                        update5.setId(introUser4.getId());
//                                                                        update5.setCoin(introUser4.getCoin().add(priceVip6));
//                                                                        this.memberService.updateMember(update5);
                                                                        introUser5 = this.memberService.selectMemberById(introUser4.getIntroUser());
                                                                        if(introUser5!=null&&introUser5.getIsVip()==3){
                                                                            //新增收益记录
                                                                            coin5=new Coin();
                                                                            coin5.setCreated(DateUtils.getNowDate());
                                                                            coin5.setType(0);
                                                                            coin5.setStatus(0);
                                                                            coin5.setMemberId(introUser5.getId());
                                                                            coin5.setNum(pricePush3);
                                                                            coin5.setResId(orderNo);
                                                                            coin5.setOrderPrice(payLog.getPrice());
                                                                            this.coinService.insertHaoqiCoinRecord(coin4);
//                                                                            update6 = new Member();
//                                                                            update6.setId(introUser5.getId());
//                                                                            update6.setCoin(introUser5.getCoin().add(pricePush3));
//                                                                            this.memberService.updateMember(update6);
                                                                        }
                                                                        break;
                                                                }
                                                            }
                                                            break;
                                                        case 3:
                                                            //新增收益记录
                                                            coin3=new Coin();
                                                            coin3.setCreated(DateUtils.getNowDate());
                                                            coin3.setType(0);
                                                            coin3.setStatus(0);
                                                            coin3.setMemberId(introUser3.getId());
                                                            coin3.setNum(priceVip6);
                                                            coin3.setResId(orderNo);
                                                            coin3.setOrderPrice(payLog.getPrice());
                                                            this.coinService.insertHaoqiCoinRecord(coin3);
//                                                            update4 = new Member();
//                                                            update4.setId(introUser3.getId());
//                                                            update4.setCoin(introUser3.getCoin().add(pricePush2));
//                                                            this.memberService.updateMember(update4);
                                                            introUser4 = this.memberService.selectMemberById(introUser3.getIntroUser());
                                                            if(introUser4!=null&&introUser4.getIsVip()==3){
                                                                //新增收益记录
                                                                coin4=new Coin();
                                                                coin4.setCreated(DateUtils.getNowDate());
                                                                coin4.setType(0);
                                                                coin4.setStatus(0);
                                                                coin4.setMemberId(introUser4.getId());
                                                                coin4.setNum(pricePush3);
                                                                coin4.setResId(orderNo);
                                                                coin4.setOrderPrice(payLog.getPrice());
                                                                this.coinService.insertHaoqiCoinRecord(coin4);
//                                                                update5 = new Member();
//                                                                update5.setId(introUser4.getId());
//                                                                update5.setCoin(introUser4.getCoin().add(pricePush3));
//                                                                this.memberService.updateMember(update5);
                                                            }
                                                            break;
                                                    }
                                                }
                                                break;
                                            case 3:
                                                //新增收益记录
                                                coin2=new Coin();
                                                coin2.setCreated(DateUtils.getNowDate());
                                                coin2.setType(0);
                                                coin2.setStatus(0);
                                                coin2.setMemberId(introUser2.getId());
                                                coin2.setNum(priceVip5);
                                                coin2.setResId(orderNo);
                                                coin2.setOrderPrice(payLog.getPrice());
                                                this.coinService.insertHaoqiCoinRecord(coin2);
//                                                update3 = new Member();
//                                                update3.setId(introUser2.getId());
//                                                update3.setCoin(introUser2.getCoin().add(priceVip5));
//                                                this.memberService.updateMember(update3);
                                                introUser3 = this.memberService.selectMemberById(introUser2.getIntroUser());
                                                if(introUser3!=null&&introUser3.getIsVip()==3){
                                                    coin3=new Coin();
                                                    coin3.setCreated(DateUtils.getNowDate());
                                                    coin3.setType(0);
                                                    coin3.setStatus(0);
                                                    coin3.setMemberId(introUser3.getId());
                                                    coin3.setNum(pricePush3);
                                                    coin3.setResId(orderNo);
                                                    coin3.setOrderPrice(payLog.getPrice());
                                                    this.coinService.insertHaoqiCoinRecord(coin3);
//                                                    update4 = new Member();
//                                                    update4.setId(introUser3.getId());
//                                                    update4.setCoin(introUser3.getCoin().add(pricePush3));
//                                                    this.memberService.updateMember(update4);
                                                }
                                                break;
                                        }
                                    }
                                    break;
                                case 2:
                                    coin1=new Coin();
                                    coin1.setCreated(DateUtils.getNowDate());
                                    coin1.setType(0);
                                    coin1.setStatus(0);
                                    coin1.setMemberId(introUser1.getId());
                                    coin1.setNum(priceVip4);
                                    coin1.setResId(orderNo);
                                    coin1.setOrderPrice(payLog.getPrice());
                                    this.coinService.insertHaoqiCoinRecord(coin1);
//                                    update2 = new Member();
//                                    update2.setId(introUser1.getId());
//                                    update2.setCoin(introUser1.getCoin().add(priceVip4));
//                                    this.memberService.updateMember(update2);
                                    introUser2 = this.memberService.selectMemberById(introUser1.getIntroUser());
                                    if(introUser2!=null){
                                        switch (introUser2.getIsVip()){
                                            case 2:
                                                coin2=new Coin();
                                                coin2.setCreated(DateUtils.getNowDate());
                                                coin2.setType(0);
                                                coin2.setStatus(0);
                                                coin2.setMemberId(introUser2.getId());
                                                coin2.setNum(pricePush2);
                                                coin2.setResId(orderNo);
                                                coin2.setOrderPrice(payLog.getPrice());
                                                this.coinService.insertHaoqiCoinRecord(coin2);
//                                                update3 = new Member();
//                                                update3.setId(introUser2.getId());
//                                                update3.setCoin(introUser2.getCoin().add(pricePush2));
//                                                this.memberService.updateMember(update3);
                                                introUser3 = this.memberService.selectMemberById(introUser2.getIntroUser());
                                                if(introUser3!=null){
                                                    switch (introUser3.getIsVip()){
                                                        case 3:
                                                            coin3=new Coin();
                                                            coin3.setCreated(DateUtils.getNowDate());
                                                            coin3.setType(0);
                                                            coin3.setStatus(0);
                                                            coin3.setMemberId(introUser3.getId());
                                                            coin3.setNum(priceVip6);
                                                            coin3.setResId(orderNo);
                                                            coin3.setOrderPrice(payLog.getPrice());
                                                            this.coinService.insertHaoqiCoinRecord(coin3);
//                                                            update4 = new Member();
//                                                            update4.setId(introUser3.getId());
//                                                            update4.setCoin(introUser3.getCoin().add(pricePush2));
//                                                            this.memberService.updateMember(update4);
                                                            introUser4 = this.memberService.selectMemberById(introUser3.getIntroUser());
                                                            if(introUser4!=null&&introUser4.getIsVip()==3){
                                                                coin4=new Coin();
                                                                coin4.setCreated(DateUtils.getNowDate());
                                                                coin4.setType(0);
                                                                coin4.setStatus(0);
                                                                coin4.setMemberId(introUser4.getId());
                                                                coin4.setNum(pricePush3);
                                                                coin4.setResId(orderNo);
                                                                coin4.setOrderPrice(payLog.getPrice());
                                                                this.coinService.insertHaoqiCoinRecord(coin4);
//                                                                update5 = new Member();
//                                                                update5.setId(introUser4.getId());
//                                                                update5.setCoin(introUser4.getCoin().add(pricePush3));
//                                                                this.memberService.updateMember(update5);
                                                            }
                                                            break;
                                                    }
                                                }
                                                break;
                                            case 3:
                                                coin2=new Coin();
                                                coin2.setCreated(DateUtils.getNowDate());
                                                coin2.setType(0);
                                                coin2.setStatus(0);
                                                coin2.setMemberId(introUser2.getId());
                                                coin2.setNum(priceVip5);
                                                coin2.setResId(orderNo);
                                                coin2.setOrderPrice(payLog.getPrice());
                                                this.coinService.insertHaoqiCoinRecord(coin2);
//                                                update3 = new Member();
//                                                update3.setId(introUser2.getId());
//                                                update3.setCoin(introUser2.getCoin().add(priceVip5));
//                                                this.memberService.updateMember(update3);
                                                introUser3 = this.memberService.selectMemberById(introUser2.getIntroUser());
                                                if(introUser3!=null&&introUser3.getIsVip()==3){
                                                    coin3=new Coin();
                                                    coin3.setCreated(DateUtils.getNowDate());
                                                    coin3.setType(0);
                                                    coin3.setStatus(0);
                                                    coin3.setMemberId(introUser3.getId());
                                                    coin3.setNum(pricePush3);
                                                    coin3.setResId(orderNo);
                                                    coin3.setOrderPrice(payLog.getPrice());
                                                    this.coinService.insertHaoqiCoinRecord(coin3);
//                                                    update4 = new Member();
//                                                    update4.setId(introUser3.getId());
//                                                    update4.setCoin(introUser3.getCoin().add(pricePush3));
//                                                    this.memberService.updateMember(update4);
                                                }
                                                break;
                                        }
                                    }
                                    break;
                                case 3:
                                    coin2=new Coin();
                                    coin2.setCreated(DateUtils.getNowDate());
                                    coin2.setType(0);
                                    coin2.setStatus(0);
                                    coin2.setMemberId(introUser1.getId());
                                    coin2.setNum(priceVip5);
                                    coin2.setResId(orderNo);
                                    coin2.setOrderPrice(payLog.getPrice());
                                    this.coinService.insertHaoqiCoinRecord(coin2);
//                                    update3 = new Member();
//                                    update3.setId(introUser1.getId());
//                                    update3.setCoin(introUser1.getCoin().add(priceVip5));
//                                    this.memberService.updateMember(update3);
                                    introUser3 = this.memberService.selectMemberById(introUser1.getIntroUser());
                                    if(introUser3!=null&&introUser3.getIsVip()==3){
                                        coin3=new Coin();
                                        coin3.setCreated(DateUtils.getNowDate());
                                        coin3.setType(0);
                                        coin3.setStatus(0);
                                        coin3.setMemberId(introUser3.getId());
                                        coin3.setNum(pricePush3);
                                        coin3.setResId(orderNo);
                                        coin3.setOrderPrice(payLog.getPrice());
                                        this.coinService.insertHaoqiCoinRecord(coin3);
//                                        update4 = new Member();
//                                        update4.setId(introUser1.getId());
//                                        update4.setCoin(introUser1.getCoin().add(pricePush3));
//                                        this.memberService.updateMember(update4);
                                    }
                                    break;
                            }
                        }
                        break;
                    case 2:
                        //新增记录
                        coin = new Coin();
                        coin.setCreated(DateUtils.getNowDate());
                        coin.setType(0);
                        coin.setStatus(0);
                        coin.setMemberId(introUser.getId());
                        coin.setNum(priceVip2);
                        coin.setResId(orderNo);
                        coin.setOrderPrice(payLog.getPrice());
                        this.coinService.insertHaoqiCoinRecord(coin);
//                        update1 = new Member();
//                        update1.setId(introUser.getId());
//                        update1.setCoin(introUser.getCoin().add(priceVip2));
//                        this.memberService.updateMember(update1);
                        introUser1 = this.memberService.selectMemberById(introUser.getIntroUser());
                        if(introUser1!=null){
                            switch (introUser1.getIsVip()){
                                case 2:
                                    coin1=new Coin();
                                    coin1.setCreated(DateUtils.getNowDate());
                                    coin1.setType(0);
                                    coin1.setStatus(0);
                                    coin1.setMemberId(introUser1.getId());
                                    coin1.setNum(pricePush2);
                                    coin1.setResId(orderNo);
                                    coin1.setOrderPrice(payLog.getPrice());
                                    this.coinService.insertHaoqiCoinRecord(coin1);
//                                    update2 = new Member();
//                                    update2.setId(introUser1.getId());
//                                    update2.setCoin(introUser1.getCoin().add(pricePush2));
//                                    this.memberService.updateMember(update2);
                                    introUser2 = this.memberService.selectMemberById(introUser1.getIntroUser());
                                    if(introUser2!=null){
                                        switch (introUser2.getIsVip()){
                                            case 3:
                                                coin2=new Coin();
                                                coin2.setCreated(DateUtils.getNowDate());
                                                coin2.setType(0);
                                                coin2.setStatus(0);
                                                coin2.setMemberId(introUser2.getId());
                                                coin2.setNum(priceVip5);
                                                coin2.setResId(orderNo);
                                                coin2.setOrderPrice(payLog.getPrice());
                                                this.coinService.insertHaoqiCoinRecord(coin2);
//                                                update3 = new Member();
//                                                update3.setId(introUser2.getId());
//                                                update3.setCoin(introUser2.getCoin().add(priceVip5));
//                                                this.memberService.updateMember(update3);
                                                introUser3 = this.memberService.selectMemberById(introUser2.getIntroUser());
                                                if(introUser3!=null&&introUser3.getIsVip()==3){
                                                    coin3=new Coin();
                                                    coin3.setCreated(DateUtils.getNowDate());
                                                    coin3.setType(0);
                                                    coin3.setStatus(0);
                                                    coin3.setMemberId(introUser3.getId());
                                                    coin3.setNum(pricePush3);
                                                    coin3.setResId(orderNo);
                                                    coin3.setOrderPrice(payLog.getPrice());
                                                    this.coinService.insertHaoqiCoinRecord(coin3);
//                                                    update4 = new Member();
//                                                    update4.setId(introUser3.getId());
//                                                    update4.setCoin(introUser3.getCoin().add(pricePush3));
//                                                    this.memberService.updateMember(update4);
                                                }
                                                break;
                                        }
                                    }
                                    break;
                                case 3:
                                    coin2=new Coin();
                                    coin2.setCreated(DateUtils.getNowDate());
                                    coin2.setType(0);
                                    coin2.setStatus(0);
                                    coin2.setMemberId(introUser1.getId());
                                    coin2.setNum(priceVip5);
                                    coin2.setResId(orderNo);
                                    coin2.setOrderPrice(payLog.getPrice());
                                    this.coinService.insertHaoqiCoinRecord(coin2);
//                                    update3 = new Member();
//                                    update3.setId(introUser1.getId());
//                                    update3.setCoin(introUser1.getCoin().add(priceVip5));
//                                    this.memberService.updateMember(update3);
                                    introUser3 = this.memberService.selectMemberById(introUser1.getIntroUser());
                                    if(introUser3!=null&&introUser3.getIsVip()==3){
                                        coin3=new Coin();
                                        coin3.setCreated(DateUtils.getNowDate());
                                        coin3.setType(0);
                                        coin3.setStatus(0);
                                        coin3.setMemberId(introUser3.getId());
                                        coin3.setNum(pricePush3);
                                        coin3.setResId(orderNo);
                                        coin3.setOrderPrice(payLog.getPrice());
                                        this.coinService.insertHaoqiCoinRecord(coin3);
//                                        update4 = new Member();
//                                        update4.setId(introUser1.getId());
//                                        update4.setCoin(introUser1.getCoin().add(pricePush3));
//                                        this.memberService.updateMember(update4);
                                    }
                                    break;
                            }
                        }
                        break;
                    case 3:
                        //新增记录
                        coin = new Coin();
                        coin.setCreated(DateUtils.getNowDate());
                        coin.setType(0);
                        coin.setStatus(0);
                        coin.setMemberId(introUser.getId());
                        coin.setNum(priceVip3);
                        coin.setResId(orderNo);
                        coin.setOrderPrice(payLog.getPrice());
                        this.coinService.insertHaoqiCoinRecord(coin);
//                        update1 = new Member();
//                        update1.setId(introUser.getId());
//                        update1.setCoin(introUser.getCoin().add(priceVip3));
//                        this.memberService.updateMember(update1);
                        introUser3 = this.memberService.selectMemberById(introUser.getIntroUser());
                        if(introUser3!=null&&introUser3.getIsVip()==3){
                            coin3=new Coin();
                            coin3.setCreated(DateUtils.getNowDate());
                            coin3.setType(0);
                            coin3.setStatus(0);
                            coin3.setMemberId(introUser3.getId());
                            coin3.setNum(pricePush3);
                            coin3.setResId(orderNo);
                            coin3.setOrderPrice(payLog.getPrice());
                            this.coinService.insertHaoqiCoinRecord(coin3);
//                            update4 = new Member();
//                            update4.setId(introUser3.getId());
//                            update4.setCoin(introUser3.getCoin().add(pricePush3));
//                            this.memberService.updateMember(update4);
                        }
                        break;
                }
                break;
            case 1:
                switch (introUser.getIsVip()){
                    case 1:
                        //新增记录
                        coin = new Coin();
                        coin.setCreated(DateUtils.getNowDate());
                        coin.setType(0);
                        coin.setStatus(0);
                        coin.setMemberId(introUser.getId());
                        coin.setNum(pricePush1);
                        coin.setResId(orderNo);
                        coin.setOrderPrice(payLog.getPrice());
                        this.coinService.insertHaoqiCoinRecord(coin);
//                        update1 = new Member();
//                        update1.setId(introUser.getId());
//                        update1.setCoin(introUser.getCoin().add(pricePush1));
//                        this.memberService.updateMember(update1);
                        introUser1 = this.memberService.selectMemberById(introUser.getIntroUser());
                        if(introUser1!=null){
                            switch (introUser1.getIsVip()){
                                case 2:
                                    coin1=new Coin();
                                    coin1.setCreated(DateUtils.getNowDate());
                                    coin1.setType(0);
                                    coin1.setStatus(0);
                                    coin1.setMemberId(introUser1.getId());
                                    coin1.setNum(priceVip4);
                                    coin1.setResId(orderNo);
                                    coin1.setOrderPrice(payLog.getPrice());
                                    this.coinService.insertHaoqiCoinRecord(coin1);
//                                    update2 = new Member();
//                                    update2.setId(introUser1.getId());
//                                    update2.setCoin(introUser1.getCoin().add(priceVip4));
//                                    this.memberService.updateMember(update2);
                                    introUser2 = this.memberService.selectMemberById(introUser1.getIntroUser());
                                    if(introUser2!=null){
                                        switch (introUser2.getIsVip()){
                                            case 2:
                                                coin2=new Coin();
                                                coin2.setCreated(DateUtils.getNowDate());
                                                coin2.setType(0);
                                                coin2.setStatus(0);
                                                coin2.setMemberId(introUser2.getId());
                                                coin2.setNum(pricePush2);
                                                coin2.setResId(orderNo);
                                                coin2.setOrderPrice(payLog.getPrice());
                                                this.coinService.insertHaoqiCoinRecord(coin2);
//                                                update3 = new Member();
//                                                update3.setId(introUser2.getId());
//                                                update3.setCoin(introUser2.getCoin().add(pricePush2));
//                                                this.memberService.updateMember(update3);
                                                introUser3 = this.memberService.selectMemberById(introUser2.getIntroUser());
                                                if(introUser3!=null){
                                                    switch (introUser3.getIsVip()){
                                                        case 3:
                                                            coin3=new Coin();
                                                            coin3.setCreated(DateUtils.getNowDate());
                                                            coin3.setType(0);
                                                            coin3.setStatus(0);
                                                            coin3.setMemberId(introUser3.getId());
                                                            coin3.setNum(priceVip6);
                                                            coin3.setResId(orderNo);
                                                            coin3.setOrderPrice(payLog.getPrice());
                                                            this.coinService.insertHaoqiCoinRecord(coin3);
//                                                            update4 = new Member();
//                                                            update4.setId(introUser3.getId());
//                                                            update4.setCoin(introUser3.getCoin().add(pricePush2));
//                                                            this.memberService.updateMember(update4);
                                                            introUser4 = this.memberService.selectMemberById(introUser3.getIntroUser());
                                                            if(introUser4!=null&&introUser4.getIsVip()==3){
                                                                coin4=new Coin();
                                                                coin4.setCreated(DateUtils.getNowDate());
                                                                coin4.setType(0);
                                                                coin4.setStatus(0);
                                                                coin4.setMemberId(introUser4.getId());
                                                                coin4.setNum(pricePush3);
                                                                coin4.setResId(orderNo);
                                                                coin4.setOrderPrice(payLog.getPrice());
                                                                this.coinService.insertHaoqiCoinRecord(coin4);
//                                                                update5 = new Member();
//                                                                update5.setId(introUser4.getId());
//                                                                update5.setCoin(introUser4.getCoin().add(pricePush3));
//                                                                this.memberService.updateMember(update5);
                                                            }
                                                            break;
                                                    }
                                                }
                                                break;
                                            case 3:
                                                coin2=new Coin();
                                                coin2.setCreated(DateUtils.getNowDate());
                                                coin2.setType(0);
                                                coin2.setStatus(0);
                                                coin2.setMemberId(introUser2.getId());
                                                coin2.setNum(priceVip5);
                                                coin2.setResId(orderNo);
                                                coin2.setOrderPrice(payLog.getPrice());
                                                this.coinService.insertHaoqiCoinRecord(coin2);
//                                                update3 = new Member();
//                                                update3.setId(introUser2.getId());
//                                                update3.setCoin(introUser2.getCoin().add(priceVip5));
//                                                this.memberService.updateMember(update3);
                                                introUser3 = this.memberService.selectMemberById(introUser2.getIntroUser());
                                                if(introUser3!=null&&introUser3.getIsVip()==3){
                                                    coin3=new Coin();
                                                    coin3.setCreated(DateUtils.getNowDate());
                                                    coin3.setType(0);
                                                    coin3.setStatus(0);
                                                    coin3.setMemberId(introUser3.getId());
                                                    coin3.setNum(pricePush3);
                                                    coin3.setResId(orderNo);
                                                    coin3.setOrderPrice(payLog.getPrice());
                                                    this.coinService.insertHaoqiCoinRecord(coin3);
//                                                    update4 = new Member();
//                                                    update4.setId(introUser3.getId());
//                                                    update4.setCoin(introUser3.getCoin().add(pricePush3));
//                                                    this.memberService.updateMember(update4);
                                                }
                                                break;
                                        }
                                    }
                                    break;
                                case 3:
                                    coin2=new Coin();
                                    coin2.setCreated(DateUtils.getNowDate());
                                    coin2.setType(0);
                                    coin2.setStatus(0);
                                    coin2.setMemberId(introUser1.getId());
                                    coin2.setNum(priceVip5);
                                    coin2.setResId(orderNo);
                                    coin2.setOrderPrice(payLog.getPrice());
                                    this.coinService.insertHaoqiCoinRecord(coin2);
//                                    update3 = new Member();
//                                    update3.setId(introUser1.getId());
//                                    update3.setCoin(introUser1.getCoin().add(priceVip5));
//                                    this.memberService.updateMember(update3);
                                    introUser3 = this.memberService.selectMemberById(introUser1.getIntroUser());
                                    if(introUser3!=null&&introUser3.getIsVip()==3){
                                        coin3=new Coin();
                                        coin3.setCreated(DateUtils.getNowDate());
                                        coin3.setType(0);
                                        coin3.setStatus(0);
                                        coin3.setMemberId(introUser3.getId());
                                        coin3.setNum(pricePush3);
                                        coin3.setResId(orderNo);
                                        coin3.setOrderPrice(payLog.getPrice());
                                        this.coinService.insertHaoqiCoinRecord(coin3);
//                                        update4 = new Member();
//                                        update4.setId(introUser1.getId());
//                                        update4.setCoin(introUser1.getCoin().add(pricePush3));
//                                        this.memberService.updateMember(update4);
                                    }
                                    break;
                            }
                        }
                        break;
                    case 2:
                        //新增记录
                        coin = new Coin();
                        coin.setCreated(DateUtils.getNowDate());
                        coin.setType(0);
                        coin.setStatus(0);
                        coin.setMemberId(introUser.getId());
                        coin.setNum(priceVip4);
                        coin.setResId(orderNo);
                        coin.setOrderPrice(payLog.getPrice());
                        this.coinService.insertHaoqiCoinRecord(coin);
//                        update1 = new Member();
//                        update1.setId(introUser.getId());
//                        update1.setCoin(introUser.getCoin().add(priceVip4));
//                        this.memberService.updateMember(update1);
                        introUser1 = this.memberService.selectMemberById(introUser.getIntroUser());
                        if(introUser1!=null){
                            switch (introUser1.getIsVip()){
                                case 2:
                                    coin1=new Coin();
                                    coin1.setCreated(DateUtils.getNowDate());
                                    coin1.setType(0);
                                    coin1.setStatus(0);
                                    coin1.setMemberId(introUser1.getId());
                                    coin1.setNum(pricePush2);
                                    coin1.setResId(orderNo);
                                    coin1.setOrderPrice(payLog.getPrice());
                                    this.coinService.insertHaoqiCoinRecord(coin1);
//                                    update2 = new Member();
//                                    update2.setId(introUser1.getId());
//                                    update2.setCoin(introUser1.getCoin().add(pricePush2));
//                                    this.memberService.updateMember(update2);
                                    introUser2 = this.memberService.selectMemberById(introUser1.getIntroUser());
                                    if(introUser2!=null){
                                        switch (introUser2.getIsVip()){
                                            case 3:
                                                coin2=new Coin();
                                                coin2.setCreated(DateUtils.getNowDate());
                                                coin2.setType(0);
                                                coin2.setStatus(0);
                                                coin2.setMemberId(introUser2.getId());
                                                coin2.setNum(priceVip5);
                                                coin2.setResId(orderNo);
                                                coin2.setOrderPrice(payLog.getPrice());
                                                this.coinService.insertHaoqiCoinRecord(coin2);
//                                                update3 = new Member();
//                                                update3.setId(introUser2.getId());
//                                                update3.setCoin(introUser2.getCoin().add(priceVip5));
//                                                this.memberService.updateMember(update3);
                                                introUser3 = this.memberService.selectMemberById(introUser2.getIntroUser());
                                                if(introUser3!=null&&introUser3.getIsVip()==3){
                                                    coin3=new Coin();
                                                    coin3.setCreated(DateUtils.getNowDate());
                                                    coin3.setType(0);
                                                    coin3.setStatus(0);
                                                    coin3.setMemberId(introUser3.getId());
                                                    coin3.setNum(pricePush3);
                                                    coin3.setResId(orderNo);
                                                    coin3.setOrderPrice(payLog.getPrice());
                                                    this.coinService.insertHaoqiCoinRecord(coin3);
//                                                    update4 = new Member();
//                                                    update4.setId(introUser3.getId());
//                                                    update4.setCoin(introUser3.getCoin().add(pricePush3));
//                                                    this.memberService.updateMember(update4);
                                                }
                                                break;
                                        }
                                    }
                                    break;
                                case 3:
                                    coin2=new Coin();
                                    coin2.setCreated(DateUtils.getNowDate());
                                    coin2.setType(0);
                                    coin2.setStatus(0);
                                    coin2.setMemberId(introUser1.getId());
                                    coin2.setNum(priceVip5);
                                    coin2.setResId(orderNo);
                                    coin2.setOrderPrice(payLog.getPrice());
                                    this.coinService.insertHaoqiCoinRecord(coin2);
//                                    update3 = new Member();
//                                    update3.setId(introUser1.getId());
//                                    update3.setCoin(introUser1.getCoin().add(priceVip5));
//                                    this.memberService.updateMember(update3);
                                    introUser3 = this.memberService.selectMemberById(introUser1.getIntroUser());
                                    if(introUser3!=null&&introUser3.getIsVip()==3){
                                        coin3=new Coin();
                                        coin3.setCreated(DateUtils.getNowDate());
                                        coin3.setType(0);
                                        coin3.setStatus(0);
                                        coin3.setMemberId(introUser3.getId());
                                        coin3.setNum(pricePush3);
                                        coin3.setResId(orderNo);
                                        coin3.setOrderPrice(payLog.getPrice());
                                        this.coinService.insertHaoqiCoinRecord(coin3);
//                                        update4 = new Member();
//                                        update4.setId(introUser1.getId());
//                                        update4.setCoin(introUser1.getCoin().add(pricePush3));
//                                        this.memberService.updateMember(update4);
                                    }
                                    break;
                            }
                        }
                        break;
                    case 3:
                        //新增记录
                        coin = new Coin();
                        coin.setCreated(DateUtils.getNowDate());
                        coin.setType(0);
                        coin.setStatus(0);
                        coin.setMemberId(introUser.getId());
                        coin.setNum(priceVip5);
                        coin.setResId(orderNo);
                        coin.setOrderPrice(payLog.getPrice());
                        this.coinService.insertHaoqiCoinRecord(coin);
//                        update1 = new Member();
//                        update1.setId(introUser.getId());
//                        update1.setCoin(introUser.getCoin().add(priceVip5));
//                        this.memberService.updateMember(update1);
                        introUser3 = this.memberService.selectMemberById(introUser.getIntroUser());
                        if(introUser3!=null&&introUser3.getIsVip()==3){
                            coin3=new Coin();
                            coin3.setCreated(DateUtils.getNowDate());
                            coin3.setType(0);
                            coin3.setStatus(0);
                            coin3.setMemberId(introUser3.getId());
                            coin3.setNum(pricePush3);
                            coin3.setResId(orderNo);
                            coin3.setOrderPrice(payLog.getPrice());
                            this.coinService.insertHaoqiCoinRecord(coin3);
//                            update4 = new Member();
//                            update4.setId(introUser3.getId());
//                            update4.setCoin(introUser3.getCoin().add(pricePush3));
//                            this.memberService.updateMember(update4);
                        }
                        break;
                }
                break;
            case 2:
                switch (introUser.getIsVip()){
                    case 2:
                        coin1=new Coin();
                        coin1.setCreated(DateUtils.getNowDate());
                        coin1.setType(0);
                        coin1.setStatus(0);
                        coin1.setMemberId(introUser.getId());
                        coin1.setNum(pricePush2);
                        coin1.setResId(orderNo);
                        coin1.setOrderPrice(payLog.getPrice());
                        this.coinService.insertHaoqiCoinRecord(coin1);
//                        update2 = new Member();
//                        update2.setId(introUser.getId());
//                        update2.setCoin(introUser.getCoin().add(pricePush2));
//                        this.memberService.updateMember(update2);
                        introUser2 = this.memberService.selectMemberById(introUser.getIntroUser());
                        if(introUser2!=null){
                            switch (introUser2.getIsVip()){
                                case 3:
                                    coin2=new Coin();
                                    coin2.setCreated(DateUtils.getNowDate());
                                    coin2.setType(0);
                                    coin2.setStatus(0);
                                    coin2.setMemberId(introUser2.getId());
                                    coin2.setNum(priceVip5);
                                    coin2.setResId(orderNo);
                                    coin2.setOrderPrice(payLog.getPrice());
                                    this.coinService.insertHaoqiCoinRecord(coin2);
//                                    update3 = new Member();
//                                    update3.setId(introUser2.getId());
//                                    update3.setCoin(introUser2.getCoin().add(priceVip5));
//                                    this.memberService.updateMember(update3);
                                    introUser3 = this.memberService.selectMemberById(introUser2.getIntroUser());
                                    if(introUser3!=null&&introUser3.getIsVip()==3){
                                        coin3=new Coin();
                                        coin3.setCreated(DateUtils.getNowDate());
                                        coin3.setType(0);
                                        coin3.setStatus(0);
                                        coin3.setMemberId(introUser3.getId());
                                        coin3.setNum(pricePush3);
                                        coin3.setResId(orderNo);
                                        coin3.setOrderPrice(payLog.getPrice());
                                        this.coinService.insertHaoqiCoinRecord(coin3);
//                                        update4 = new Member();
//                                        update4.setId(introUser3.getId());
//                                        update4.setCoin(introUser3.getCoin().add(pricePush3));
//                                        this.memberService.updateMember(update4);
                                    }
                                    break;
                            }
                        }
                        break;
                    case 3:
                        coin2=new Coin();
                        coin2.setCreated(DateUtils.getNowDate());
                        coin2.setType(0);
                        coin2.setStatus(0);
                        coin2.setMemberId(introUser.getId());
                        coin2.setNum(priceVip5);
                        coin2.setResId(orderNo);
                        coin2.setOrderPrice(payLog.getPrice());
                        this.coinService.insertHaoqiCoinRecord(coin2);
//                        update3 = new Member();
//                        update3.setId(introUser.getId());
//                        update3.setCoin(introUser.getCoin().add(priceVip5));
//                        this.memberService.updateMember(update3);
                        introUser3 = this.memberService.selectMemberById(introUser.getIntroUser());
                        if(introUser3!=null&&introUser3.getIsVip()==3){
                            coin3=new Coin();
                            coin3.setCreated(DateUtils.getNowDate());
                            coin3.setType(0);
                            coin3.setStatus(0);
                            coin3.setMemberId(introUser3.getId());
                            coin3.setNum(pricePush3);
                            coin3.setResId(orderNo);
                            coin3.setOrderPrice(payLog.getPrice());
                            this.coinService.insertHaoqiCoinRecord(coin3);
//                            update4 = new Member();
//                            update4.setId(introUser3.getId());
//                            update4.setCoin(introUser3.getCoin().add(pricePush3));
//                            this.memberService.updateMember(update4);
                        }
                        break;
                }
                break;
            case 3:
                switch (introUser.getIsVip()){
                    case 3:
                        coin3=new Coin();
                        coin3.setCreated(DateUtils.getNowDate());
                        coin3.setType(0);
                        coin3.setStatus(0);
                        coin3.setMemberId(introUser.getId());
                        coin3.setNum(pricePush3);
                        coin3.setResId(orderNo);
                        coin3.setOrderPrice(payLog.getPrice());
                        this.coinService.insertHaoqiCoinRecord(coin3);
//                        update4 = new Member();
//                        update4.setId(introUser.getId());
//                        update4.setCoin(introUser.getCoin().add(pricePush3));
//                        this.memberService.updateMember(update4);
                        break;
                }
                break;
        }
    }

    @Override
    public List<Member> seMemberList(String uid) {
        return memberMapper.seMemberList(uid);
    }
}
